import axios, { AxiosResponse } from "axios";
import qs from "qs";

interface OptionProp {
  url: string;
  method?: "GET" | "POST";
  data?: any;
  headers?: any;
  params?: any;
}

const fetch = async (options: OptionProp): Promise<AxiosResponse> => {
  if (!options.method) {
    options.method = "GET";
  }
  options.headers = {
    "Content-Type": "application/json;charset=utf-8",
    token: "ec6ef58694444b061eba7b2b1fe344ad39a781be3f7345141",
    ...(options.headers || {}),
  };

  const res = await axios(options);
  return res.data || res;
};

export default fetch;
